package model;

import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

import dao.DAO;
import dao.DAOFactory;
import dao.tables.RESPONSABILITE;

public class JComboBoxCellEditor extends AbstractCellEditor implements
	TableCellEditor {
    private static final long serialVersionUID = 8554637792600366338L;

    private JComboBox<?> jcb = null;

    @Override
    public Object getCellEditorValue() {
	return jcb.getSelectedItem();
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value,
	    boolean isSelected, int row, int col) {
	if (col == 1) {
	    jcb = new JComboBox<String>(new String[] { "M   ", "Mme ", "Mlle" });
	    jcb.setSelectedItem((String) value);
	}
	if (col == 5) {
	    DAO<RESPONSABILITE> respDao = new DAOFactory<RESPONSABILITE>()
		    .getResponsabiliteDAO();
	    jcb = new JComboBox<RESPONSABILITE>(respDao.list());
	    jcb.setSelectedItem(value);

	}
	return jcb;
    }
}
